// trasfer data over i2c interface
// copy variables to i2c buffer
void i2c_copy_data (void)
{
    memcpy(&out.in, &out_parm, sizeof(out.in));
    memcpy(out.ad_ch, ad_ch, sizeof(out.ad_ch));
    memcpy(out.offset_ign_chanel, offset_ign_chanel, sizeof(out.offset_ign_chanel));
    out.f_count = f_count;
    out.flow_tst_couter = flow_tst_couter;
    out.diff = diff;
    out.ign_power_up = ign_power_up;
    out.mapt = mapt;
    out.obt  = obt;
    out.bar_percent = bar_percent;
    out.pulse_crank = pulse_crank;
    out.pw_acc = pw_acc;
    out.pw_corr_per = pw_corr_per;
    out.time = time;
    out.timeinj = timeinj;
    out.timeinj_crank = timeinj_crank;
    out.time_1 = time_1;
}

//do transfer data buffer over i2c inteface
void i2c_wr_data_p(int8 pack_size)
{
            int8    *ptr = &out;
    static  int8    add;

    if (have_i2c_display) {
        //send data
        if(!add) {
            i2c_copy_data();
        }

        while (add < sizeof(out)){
            if (write_i2c_dev(I2C_DISPLAY_ADR, add, &ptr[add])) {
                have_i2c_display = 0;
                beeper(10, 5);
                break;
            }

            add ++;

            if (!(add % pack_size)) {
                break; // pack data was send
            }
        }

        if (add >= sizeof(out)) {
            add = 0; // all data was send
        }
    }
}

void i2c_rd_data_p(int8 pack_size)
{
            int8    *ptr = &in;
    static  int8    add;

    if (have_i2c_display) {
        //send data
        while (add < sizeof(in)){
            if (read_i2c_dev(I2C_DISPLAY_ADR, add, &ptr[add])) {
                have_i2c_display = 0;
                beeper(10, 5);
                break;
            }

            add ++;

            if (!(add % pack_size)) {
                break; // pack data was received
            }
        }

        if (add >= sizeof(in)) {
            add = 0; // all data was send
        }
    }
}

void i2c_rw_data (int8 pack)
{
    if (have_i2c_display) {
        i2c_wr_data_p(pack);
        i2c_rd_data_p(pack);
    }
}

